#include "AutoBoxLayout.h"
#include <QtCore/QRect>
#include <QtGui/QDesktopWidget>
#include <QtGui/QApplication>

AutoBoxLayout::AutoBoxLayout(QWidget *parent)
	: QBoxLayout(desktopDirection(),parent)
{
	//connect (QApplication::desktop(),SIGNAL(resized ( int)),this,SLOT(refreshLayout()));
	connect (QApplication::desktop(),SIGNAL(workAreaResized(int)),this,SLOT(refreshLayout()));
}

AutoBoxLayout::~AutoBoxLayout()
{

}

AutoBoxLayout::Direction AutoBoxLayout::desktopDirection() const{
	const QRect rect=QApplication::desktop()->screenGeometry();
	return rect.width()>rect.height()?QBoxLayout::LeftToRight:QBoxLayout::TopToBottom;
}

void AutoBoxLayout::refreshLayout(){
	setDirection(desktopDirection());
}